public class PiramidSortTest {

	public static void main(String[] args) {

		testObmen();
		testMaxSonValInd();
		testProseiatEl();
		testBuildPiramida();
		testCompleteSort();
		testSort();
	}

	public static void testSort() {

		System.out.print("testSort-");
		int[] ishMas0 = { 13, 15, 10, 12, 30, 11, 5, 25 };
		int[] ozhidMas0 = { 5, 10, 11, 12, 13, 15, 25, 30 };
		int[] rezMas = PiramidSort.sort(ishMas0);

		if (!isArraysEquals(rezMas, ozhidMas0)) {
			throw new RuntimeException("Faild0!");
		}

		// ///////////////////////////////////////
		int[] ishMas1 = { 13, 15, 10, 12, 30, 11, 5, 25, 5, 5, 1, 1, 1, 1, 1,
				5, 6, 7, 8, 13 };
		int[] ozhidMas1 = { 1, 1, 1, 1, 1, 5, 5, 5, 5, 6, 7, 8, 10, 11, 12, 13,
				13, 15, 25, 30 };
		rezMas = PiramidSort.sort(ishMas1);
		if (!isArraysEquals(rezMas, ozhidMas1)) {
			throw new RuntimeException("Faild1!");
		}

		System.out.println("Ok!");
	}

	public static void testCompleteSort() {
		System.out.print("testCompleteSort-");
		
		int[] ishMas = { 30, 25, 11, 13, 15, 10, 5, 12 };
		int[] ozhidMas = { 5, 10, 11, 12, 13, 15, 25, 30 };
		int[] rezMas = PiramidSort.completeSort(ishMas);
		if (!isArraysEquals(rezMas, ozhidMas)) {
			throw new RuntimeException("Faild!");
		}
		System.out.println("Ok!");
	}

	public static void testBuildPiramida() {
		System.out.print("testBuildPiramida-");
		
		int[] ishMas = { 13, 15, 10, 12, 30, 11, 5, 25 };
		int[] ozhidMas = { 30, 25, 11, 13, 15, 10, 5, 12 };
		int[] rezMas = PiramidSort.buildPiramida(ishMas);
		if (!isArraysEquals(rezMas, ozhidMas)) {
			throw new RuntimeException("Faild!");
		}
		System.out.println("Ok!");
	}

	public static void testProseiatEl() {
		System.out.print("testProseiatEl-");
		int[] ishMas0 = { 1, 2, 3 };
		int[] ozhidMas0 = { 1, 2, 3 };

		int[] rezMas = PiramidSort.proseiatEl(ishMas0, 1, 0);
		if (!isArraysEquals(rezMas, ozhidMas0)) {
			throw new RuntimeException("Faild 0!");
		}
		//////
		int[] ishMas1 = { 1, 2, 3 };
		int[] ozhidMas1 = { 2, 1, 3 };
		rezMas = PiramidSort.proseiatEl(ishMas1, 2, 0);
		if (!isArraysEquals(rezMas, ozhidMas1)) {
			throw new RuntimeException("Faild 1!");
		}
		//////
		int[] ishMas2 = { 1, 2, 3 };
		int[] ozhidMas2 = { 3, 2, 1 };
		rezMas = PiramidSort.proseiatEl(ishMas2, 3, 0);
		if (!isArraysEquals(rezMas, ozhidMas2)) {
			throw new RuntimeException("Faild 2!");
		}
		//////
		int[] ishMas3 = { 13, 15, 10, 12, 30, 11, 5, 25 };
		int[] ozhidMas3 = { 13, 15, 10, 25, 30, 11, 5, 12 };
		rezMas = PiramidSort.proseiatEl(ishMas3, 8, 3);
		if (!isArraysEquals(rezMas, ozhidMas3)) {
			throw new RuntimeException("Faild 3!");
		}

		System.out.println("Ok!");
	}

	public static void testMaxSonValInd() {
		System.out.print("testMaxSonValInd-");
		int[] ishMas = { 1, 2, 3 };
		int ozhid = 2;
		int rez = PiramidSort.maxSonValInd(ishMas, 3, 0);
		if (rez != ozhid) {
			throw new RuntimeException("Faild 0!");
		}
		//////
		ozhid = 1;
		rez = PiramidSort.maxSonValInd(ishMas, 2, 0);
		if (rez != ozhid) {
			throw new RuntimeException("Faild 1!");
		}
		//////
		ozhid = -1;
		rez = PiramidSort.maxSonValInd(ishMas, 1, 0);
		if (rez != ozhid) {
			throw new RuntimeException("Faild 3!");
		}
		System.out.println("Ok!");
	}

	public static void testObmen() {

		System.out.print("testObmen-");
		int[] ishMas = { 1, 2 };
		int[] ozhidMas = { 2, 1 };
		int[] resMas = PiramidSort.obmen(ishMas, 0, 1);
		if (!isArraysEquals(ozhidMas, resMas)) {
			throw new RuntimeException("Faild!");
		}
		System.out.println("Ok!");
	}

	private static boolean isArraysEquals(int[] mas0, int[] mas1) {

		int len0 = mas0.length;
		int len1 = mas1.length;
		if (len0 != len1) {
			return false;
		}
		for (int i = 0; i < len0; i++) {
			if (mas0[i] != mas1[i]) {
				return false;
			}
		}
		return true;
	}

}
